# Maintainer: Konstantin Gizdov <arch at kge dot pw>
# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>

_pkgbase='intel-oneapi-compiler-dpcpp'
_pkgname="${_pkgbase}-cpp"
pkgbase="${_pkgname}-runtime"
pkgname=("${_pkgname}-runtime" "${_pkgname}-runtime-libs")
pkgver=2023.2.0
_debpkgrel=49495
pkgrel=1
_pkgdesc="Intel oneAPI Data Parallel C++ compiler"
arch=('loong64' 'x86_64')
url='https://software.intel.com/content/www/us/en/develop/tools/oneapi.html'
license=("custom")
source=("https://apt.repos.intel.com/oneapi/pool/main/${pkgname}-${pkgver}-${pkgver}-${_debpkgrel}_amd64.deb"
        "https://apt.repos.intel.com/oneapi/pool/main/${_pkgname}-common-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
        "https://apt.repos.intel.com/oneapi/pool/main/${_pkgbase}-eclipse-cfg-${pkgver}-${_debpkgrel}_all.deb"
        "https://apt.repos.intel.com/oneapi/pool/main/intel-oneapi-icc-eclipse-plugin-cpp-${pkgver}-${pkgver}-${_debpkgrel}_all.deb")
b2sums=('a721752745aa206e9001c14bece70d1d94e2a1a5a3d023ea6758d40a8d02eb9babe1b17f328b34fba04ef8925cc3c576dcccf5ea4509496c7095b7f6f42c3044'
        '4081cd232f09bc5d259e07288fd2d96a40721aaa6dcc2d716b04ca35dde86c00d4147e88449294d6545370dd126d504b42aef81feb8d07d559b98cff62d14c72'
        'd95c51afdf2d272a5d7c44634f34e1e599739dcf08b5480499c2159c5e86f7817f89594867b4eb7ca7d9022ce969be3bfa7da3a0cbf8cb2e75f8a97967e0ae37'
        '2cdc545707a1f1c7e74291dfb881d4eff0cc40f6b24594ca6dcb04e448c5f0185cb99d4cd6e97dc5c48bbdddc3f871df831033c7af286800fd0b18e5c7a649a4')
noextract=(
    "${pkgname}-${pkgver}-${pkgver}-${_debpkgrel}_amd64.deb"
    "${_pkgname}-common-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
    "${_pkgbase}-eclipse-cfg-${pkgver}-${_debpkgrel}_all.deb"
    "intel-oneapi-icc-eclipse-plugin-cpp-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
)

build() {
    mkdir "${_pkgbase}-${pkgver}"
    ar x "${srcdir}/${pkgname}-${pkgver}-${pkgver}-${_debpkgrel}_amd64.deb"
	tar xvf data.tar.xz -C "${_pkgbase}-${pkgver}"
    rm data.tar.xz

    ar x "${srcdir}/${_pkgname}-common-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
    tar xvf data.tar.xz -C "${_pkgbase}-${pkgver}"
    rm data.tar.xz

    ar x "${srcdir}/${_pkgbase}-eclipse-cfg-${pkgver}-${_debpkgrel}_all.deb"
    tar xvf data.tar.xz -C "${_pkgbase}-${pkgver}"
    rm data.tar.xz

    ar x "${srcdir}/intel-oneapi-icc-eclipse-plugin-cpp-${pkgver}-${pkgver}-${_debpkgrel}_all.deb"
    tar xvf data.tar.xz -C "${_pkgbase}-${pkgver}"
    rm data.tar.xz

    mkdir "${_pkgbase}-${pkgver}-libs"
    local _lib_path="/opt/intel/oneapi/compiler/${pkgver}/linux"
    install -d "${_pkgbase}-${pkgver}-libs/${_lib_path}/lib"
    cd "${_pkgbase}-${pkgver}/${_lib_path}/lib"
    local _lib
    for _lib in libpi_level_zero.so libsycl*; do
        mv "${_lib}" "${srcdir}/${_pkgbase}-${pkgver}-libs/${_lib_path}/lib"
    done
}

package_intel-oneapi-compiler-dpcpp-cpp-runtime-libs() {
    depends=('intel-oneapi-compiler-shared-runtime-libs' 'intel-oneapi-tbb' 'intel-oneapi-common')
    conflicts=('intel-oneapi-basekit')
    pkgdesc="${_pkgdesc}: Minimal runtime libraries"

    cp -a "${srcdir}/${_pkgbase}-${pkgver}-libs/opt" "${pkgdir}"

    # allow libs to be found
    local _lib_path='/opt/intel/oneapi/compiler'
    local _ldso_conf="${pkgdir}"/etc/ld.so.conf.d
    install -d "${_ldso_conf}"
    echo "${_lib_path}/latest/linux/lib" > "${_ldso_conf}/${pkgname}.conf"

    install -d "${pkgdir}"/usr/share/licenses/"${pkgname}"
    ln -s /usr/share/licenses/intel-oneapi "${pkgdir}"/usr/share/licenses/"${pkgname}"/oneapi
}

package_intel-oneapi-compiler-dpcpp-cpp-runtime() {
    depends=('intel-oneapi-compiler-shared-runtime' 'intel-oneapi-compiler-dpcpp-cpp-runtime-libs' 'intel-oneapi-common')
    provides=('intel-oneapi-compiler-dpcpp-cpp-common' 'intel-oneapi-compiler-dpcpp-eclipse-cfg' 'intel-oneapi-icc-eclipse-plugin-cpp')
    conflicts=('intel-oneapi-basekit')
    pkgdesc="${_pkgdesc}: Full runtime libraries and header files"

    cp -a "${srcdir}/${_pkgbase}-${pkgver}/opt" "${pkgdir}"

    # allow libs to be found
    local _lib_path='/opt/intel/oneapi/compiler'
    local _ldso_conf="${pkgdir}"/etc/ld.so.conf.d
    install -d "${_ldso_conf}"
    echo "${_lib_path}/latest/linux/lib/x64" >> "${_ldso_conf}/${pkgname}.conf"

    install -d "${pkgdir}"/usr/share/licenses/"${pkgname}"
    ln -s /usr/share/licenses/intel-oneapi "${pkgdir}"/usr/share/licenses/"${pkgname}"/oneapi
}
